package com.eogo.merchant.web;

import com.eogo.merchant.pojo.Merchant;
import com.eogo.merchant.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 商家服务
 */
@Api(value = "商家管理")
@RestController
@RequestMapping("merchant")
public class MerchantController {

    @Autowired
    private MerchantService merchantService;

    @ApiOperation(value = "商家注册" , notes = "")
    @PostMapping("insertMerchant")
    public ResponseEntity<Void> insertMerchant(@ApiParam("商家实体对象") Merchant merchant){
        merchantService.insertMerchant(merchant);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @ApiOperation(value = "商家修改" , notes = "")
    @PutMapping("updateMerchant")
    public ResponseEntity<Void> updateMerchant(@ApiParam("商家实体对象") Merchant merchant){
        merchantService.updateMerchant(merchant);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @ApiOperation(value = "根据ID查询商家信息" , notes = "")
    @GetMapping("queryMerchantById")
    public ResponseEntity<Merchant> queryMerchantById(@ApiParam("ID") @RequestParam Long id){
        Merchant merchant = merchantService.queryMerchantById(id);
        return ResponseEntity.ok(merchant);
    }

    @ApiOperation(value = "管理员审核商家")
    @PutMapping("updateMerchantByAudit")
    public ResponseEntity<Void> updateMerchantByAudit(@ApiParam("商家ID") @RequestParam("id") Long id,@ApiParam("审核状态") Integer status){
        merchantService.updateMerchantByAudit(id,status);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @ApiOperation(value = "管理员下架/上架商家")
    @PutMapping("updateMerchantBySoldout")
    public ResponseEntity<Void> updateMerchantBySoldout(@ApiParam("商家ID") @RequestParam("id") Long id,@ApiParam("审核状态") Integer soldout){
        merchantService.updateMerchantBySoldout(id,soldout);
        return ResponseEntity.status(HttpStatus.OK).build();
    }
}
